package puyu.manage.service.minio;

import io.minio.MinioClient;

import io.minio.errors.InvalidResponseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(MinioProperties.class)
@ConditionalOnProperty(name ="enabled" ,prefix = "minio",havingValue = "true",matchIfMissing = false)
public class MinioAutoConfiguration {

	@Autowired(required = false)
	private MinioProperties minioProp;


	/**
	 * 获取 MinioClient
	 */
	@Bean
	public MinioClient minioClient(){

		return MinioClient.builder()
				.endpoint(minioProp.getUrl())
				.credentials(minioProp.getAccessKey(), minioProp.getSecretKey())
				.build();
	}

}
